//
//  LevelImageView.m
//  phmall
//
//  Created by admin on 2017/10/24.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "LevelImageView.h"

@implementation LevelImageView

-(instancetype)init{
    if (self=[super init]) {
        //信用等级
        self.credit=[[UILabel alloc] init];
        self.credit.text=[NSString stringWithFormat:@"%@:",Localized(@"信用")];
        self.credit.textColor=[UIColor colorWithHexString:@"#808080"];
        self.credit.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.credit];
    }
    return self;
}
-(void)setScore:(int)score{
    _score=score;

    NSMutableDictionary *levelDict=[PublicClass countLevel:score];
    int num=[levelDict[@"num"] intValue];
    ShopLevelIcon icon=(ShopLevelIcon)[levelDict[@"icon"] intValue];
    for (int i=0; i<num; i++) {
        UIImageView *creditImg=[[UIImageView alloc] init];
        switch (icon) {
            case 0:
                creditImg.image=[UIImage imageNamed:@"灰星"];
                break;
                
            case 1:
                creditImg.image=[UIImage imageNamed:@"红星"];
                break;
                
            case 2:
                creditImg.image=[UIImage imageNamed:@"钻"];
                break;
                
            case 3:
                creditImg.image=[UIImage imageNamed:@"银冠"];
                break;
                
            case 4:
                creditImg.image=[UIImage imageNamed:@"金冠"];
                break;
            default:
                break;
        }
        [self addSubview:creditImg];
        [creditImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.credit);
            make.left.equalTo(self.credit.mas_right).with.offset(8+i*18);
            make.width.height.mas_offset(16);
        }];
    }
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.credit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).with.offset(0);
    }];
}
@end
